<div class="content">
    <div id="example_title">
        <h1>Multi Page Form</h1>
        Same form as in previous examples, but multi-paged. Click on the page link to switch pages.
    </div>
    <div id="example_view"></div>
    <div id="example_code"></div>
</div>

<!--CODE-->
<a href="javascript: form.goto(0);" style="padding-right: 10px">Page 1</a> |
<a href="javascript: form.goto(1);" style="padding: 10px">Page 2</a> |
<a href="javascript: form.goto(2);" style="padding: 10px">Page 3</a>
<div style="height: 10px;"></div>

<div id="form" style="width: 750px; height: 370px"></div>

<!--CODE-->
<script type="module">
import { w2form, query, w2ui, w2popup, w2alert } from '__W2UI_PATH__'

window.form = new w2form({
    box: '#form',
    name: 'form',
    header: 'Multi Page Form',
    url: 'server/post',
    fields: [
        { field: 'name.first', type: 'text', required: true,
            html: {
                page: 0,
                group: 'General',
                label: 'First Name',
                span: 4,
                attr: ''
            }
        },
        { field: 'name.last',  type: 'text', required: true,
            html: {
                page: 0,
                label: 'Last Name',
                span: 4,
                attr: ''
            }
        },
        { field: 'comments', type: 'textarea',
            html: {
                page: 0,
                label: 'Comments',
                span: 4,
                attr: 'style="width: 100%; height: 60px; resize: none"'
            }
        },
        { field: 'address1', type: 'text', required: true,
            html: {
                page: 1,
                group: 'Address',
                groupStyle: 'width: 100%',
                label: 'Line 1',
                span: 4,
                attr: 'style="width: 200px"'
            }
        },
        { field: 'address2', type: 'text',
            html: {
                page: 1,
                label: 'Line 2',
                span: 4,
                attr: 'style="width: 200px"'
            }
        },
        { field: 'city', type: 'text', required: true,
            html: {
                page: 1,
                label: 'City',
                span: 4,
                attr: ''
            }
        },
        { field: 'state', type: 'text', required: true,
            html: {
                page: 1,
                label: 'State',
                span: 4,
                attr: ''
            }
        },
        { field: 'zip', type: 'int', required: true,
            html: {
                page: 1,
                label: 'Zip',
                span: 4,
                attr: ''
            }
        },
        { field: 'short_bio', type: 'textarea',
            html: {
                page: 2,
                group: 'Additional Fields',
                column: 'after',
                label: 'Short Bio',
                attr: 'style="width: 90%; height: 60px; resize: none"'
            }
        },
        { field: 'talk_name', type: 'text', required: true,
            html: {
                page: 2,
                column: 'after',
                label: 'Talk Name',
                attr: 'style="width: 90%"'
            }
        },
        { field: 'description', type: 'textarea',
            html: {
                page: 2,
                column: 'after',
                label: 'Description',
                attr: 'style="width: 90%; height: 60px; resize: none"'
            }
        }
    ],
    actions: {
        Reset() {
            this.clear();
        },
        Save() {
            if (form.validate().length == 0) {
                w2popup.open({
                    title: 'Form Data',
                    with: 600,
                    height: 550,
                    body: `<pre>${JSON.stringify(this.getCleanRecord(), null, 4)}</pre>`,
                    actions: { Ok: w2popup.close }
                })
            }
        },
        custom: {
            text: '<span style="font-size: 16px">←</span> click to see data',
            class: 'custom-class',
            style: 'background-image: none; background-color: transparent; border: 0px; margin: 0 0 0 -10px;',
            onClick() {
                w2alert('Not me!! The other button')
            }
        }
    }
})
</script>
